<?PHP 
	class Form {
		function open($path,$validate=false,$method="post",$name="form1",$send_files=false){
			$form = "<form id=\"$name\" name=\"$name\" action=\"".linkForm($path)."\" method=\"$method\"";
			$form .= ($validate) ? " onSubmit=\"return \$validate(this".((application_debug_enviroment)?",true":"").");\"" : "";
			$form .= ($send_files) ? " enctype=\"multipart/form-data\"" : "";
			$form .= ">";
			return $form;
		}
		function close(){
			return "</form>";
		}
		function submit($name){
			return "<input type=\"submit\" name=\"Submit\" value=\"$name\"/>";
		}
		function datetime($name,$value){
			$values = split(" ",$value);
			$return = Form::date($name,$values[0]);
			$return .= " - ";
			$return .= Form::time($name,$values[1]);
			return $return;
		}
	    function time($name,$value){
			$value_data = split(":",$value);
			$hours = array();
			for ( $i=0; $i < 24; $i++ ){
				array_push($hours,($i+1));
			}
			$minsec = array();
			for ( $i=0; $i < 60; $i++ ){
				array_push($minsec,$i+1);
			}                                    
			$return = Form::combo($name."[]",$hours,$hours,$value_data[0]-1);
			$return .= Form::combo($name."[]",$minsec,$minsec,$value_data[1]-1); 
			$return .= Form::combo($name."[]",$minsec,$minsec,$value_data[2]-1);
			return $return;
		}
		function check($name,$value,$init=false, $enable=false){
			$return = "<input type=\"checkbox\"";
			$return .= " name=\"$name\"";
			$return .= " value=\"$value\"";
			if ($enable) $return .= " disabled=\"disabled\"";
			if($init) $return .= " checked=\"checked\"";
			$return .= "/>";
			return $return;
		}
	    function date($name,$value=NULL){
			$value_data = ($value==NULL) ? split("-",date("Y-m-d")) : split("-",$value);
			$months = array();
			$monthslabels = array();
			for ( $i=0; $i < 12; $i++ ){
				array_push($monthslabels,date("F", mktime(0,0,0,$i+1)));
				array_push($months,($i+1<10)?"0".($i+1):($i+1));
			}
			$days = array();
			for ( $i=0; $i < 31; $i++ ){
				array_push($days,($i+1<10)?"0".($i+1):($i+1));
			}
			$return = Form::combo($name."[]",$days,$days,$value_data[2]);
			$return .= Form::combo($name."[]",$months,$monthslabels,$value_data[1]);
			$return .= Form::field($name."[]",$value_data[0],4);
			return $return;
		}
		function radio($name,$value,$init=false,$label=" unnamed"){
			$return = "<input type=\"radio\"";
			$return .= " name=\"$name\"";
			$return .= " value=\"$value\"";
			if($init) $return .= " checked=\"checked\"";
			$return .= "/>".$label;
			return $return;
		}
		function combo($name,$values=array(0,1),$labels=array("dummy text 1","dummy text 2"),$selected=0){
		   	$return = "<select name=\"$name\" id=\"$name\">\n";
			for($i=0; $i<count($values); $i++){
				$return .= "<option value=\"".$values[$i]."\"";
				if($selected == $values[$i]) $return .= " selected=\"true\"";
				$return .= ">".$labels[$i]."</option>\n";
			}
			$return .= "</select>";
			return $return;
		}
		function db_combo($name,$field,$class,$actual=NULL,$params=array(),$addon=""){  
			$tmp_cntrllr = new ActiveList($class);
			$data = $tmp_cntrllr->find_all($params);
		   	$return = "<select name=\"$name\" id=\"$name\" $addon>\n";  
			for ( $i=0; $i < count($data); $i++ ){
				$temp_obj = $data[$i];
		   	   	$return .= "<option value=\"".$temp_obj->_id."\"";
				if($actual->_id == $temp_obj->_id) $return .= " selected=\"true\""; 
				$return .= ">".$temp_obj->$field."</option>\n"; 
			}
			$return .= "</select>\n";
			return $return;
		}
		function text($name,$value=null,$cols=18,$options=array()){
			$return = "<textarea rows=\"8\" cols='".$cols."' name=\"$name\" id=\"$name\"";
			if(isset($options["validate"])) $return .= " validate=\"".$options["validate"]."\"";
			$return .= ">";
			$return .= $value;
			$return .= "</textarea>";
			return $return;
		}
		function field($name,$value=null,$options=array()){
			$return = "<input type=\"text\" name=\"$name\" value=\"$value\" id=\"$name\"";
			if(isset($options["chars"])) $return .= " maxlenght=\"".$options["chars"]."\"";
			if(isset($options["size"])) $return .= " size=\"".$options["size"]."\"";
			if(isset($options["validate"])) $return .= " validate=\"".$options["validate"]."\"";
			$return .= "/>";      
			return $return;
		}    
		function file($name){
			$return = "<input type=\"file\" name=\"$name\"/>";
			return $return;
		}    
		function pass($name,$value=null,$options=array()){
			$return = "<input type=\"password\" name=\"$name\" value=\"$value\" id=\"$name\"";
			if(isset($options["chars"])) $return .= " maxlenght=\"$chars\" size=\"$chars\"";
			if(isset($options["validate"])) $return .= " validate=\"".$options["validate"]."\"";
			$return .= "/>";      
			return $return;
		}   
		function hidden($name,$value=null){
			$return = "<input type=\"hidden\" name=\"$name\" value=\"$value\" id=\"$name\"/>";      
			return $return;
		}                                           
		function label($id,$name){         
			$return = "<label for=\"$id\">".ucfirst($name)."</label>"; 
			  return $return;
		}
}
?>